package vip.ola.core.service;

import vip.ola.core.entity.MchAccount;
import vip.ola.core.entity.MchAgentpayRecord;
import vip.ola.core.entity.PayOrder;
import vip.ola.core.entity.SettRecord;

import java.util.List;
import java.util.Map;

/**
 * @author: dingzhiwei
 * @date: 17/12/4
 * @description:
 */
public interface IMchAccountService {

    List<MchAccount> listAll(int offset, int limit);

    int updateSettAmount(long mchId, long totalAmount);

    MchAccount findByMchId(Long mchId);

    /** 重置今日数据 **/
    void resetTodayAmount();


//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓更改商户账户余额（ 通过查询查询当前余额，保证当前账户没有发生变化进行更新 ）↓↓↓

    /** 当订单支付成功时,给商户账户加款,并记录资金流水 **/
    @Deprecated
    void creditToAccount(PayOrder payOrder);

    /** 加款:有银行流水 **/
    @Deprecated
    void creditToAccount(Long mchId, Long mchIncome, Long agentId, Long parentAgentId, Long orderAmount, Long agentProfit, Long parentAgentProfit, Long platProfit, Long channelCost, String requestNo, String channelOrderNo, Byte bizType);

    /** 冻结 **/
    @Deprecated
    void freezeAmount(Long mchId, Long freezeAmount);

    /** 结算成功：解冻+减款 **/
    @Deprecated
    void unFreezeAmount(Long mchId, Long amount, Long orderAmount, Long fee, String requestNo, Byte bizType);

    /** 结算失败：解冻 **/
    @Deprecated
    void unFreezeSettAmount(Long mchId, Long amount);

    /** 代付冻结, 增加代付不可用余额 **/
    @Deprecated
    void freeze4Agentpay(Long mchId, Long freezeAmount);

    /**  代付成功：解冻+减款 **/
    @Deprecated
    void unFreeze4AgentpaySuccess(Long mchId, Long amount, Long orderAmount, Long fee, String requestNo, Byte bizType, Integer agentpayPassageId);

    /**  代付失败：解冻 **/
    @Deprecated
    void unFreeze4AgentpayFail(Long mchId, Long amount);

    /**  给商户账户加钱 **/
    @Deprecated
    void credit2Account(Long mchId, Byte bizType, Long amount, String bizItem);

    /**  给商户账户加钱 **/
    @Deprecated
    void credit2Account(Long mchId, Byte bizType, Long amount, String orderId, Long orderAmount, Long fee, String bizItem);

    /**  代付充值 **/
    @Deprecated
    void recharge4Agentpay(Long mchId, Long agentId, Long mchIncome, Long orderAmount, Long agentProfit, Long parentAgentProfit, Long platProfit, Long channelCost, String requestNo, String channelOrderNo, Byte bizType, String bizItem);

    /**  给商户账户减钱 **/
    @Deprecated
    void debit2Account(Long mchId, Byte bizType, Long amount, String bizItem);

    /** 商户余额统计
     * @param mchName
     * @param mchId**/
    Map countBalance(String mchName, Long mchId);


//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑



//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓更改商户账户余额（ 采用事务行锁机制 ） ↓↓↓↓↓↓↓↓

    /** 更新商户余额和safeKey, 返回数据库最新数据Record **/
    MchAccount updateBalanceAndSafeKey(MchAccount updateMchAccount);

    /** 支付业务 / 在线充值 / 线下充值(填充订单必要信息) 订单支付完成后 处理账户信息  **/
    void changeBalanceAndInsertHistory(PayOrder payOrder, boolean isOffRecharge);

    /** 代付业务 订单支付完成后 处理账户信息 **/
    void changeBalanceAndInsertHistory(MchAgentpayRecord mar);

    /** 提现业务 处理完成后 处理账户信息 **/
    void changeBalanceAndInsertHistory(SettRecord settRecord);

    /**
     * 调账业务 处理账户信息； 当变更金额为0时不做任何操作;
     * @param mchId 商户ID
     * @param changeAmount 变更金额， 正数表示增加金额，负数表示减少金额
     * @param bizItem 类目
     */
    void changeBalanceAndInsertHistoryByPlat(Long mchId, Long changeAmount, String bizItem, String orderId, String remark);

    /**
     * 更新商户不可用余额
     * @param mchId 商户ID
     * @param bizItem 用于判断更新对象是余额不可用 / 代付余额不可用
     * @param changeUnBalance 金额
     */
    void onlyChangeUnBalance(Long mchId, String bizItem, Long changeUnBalance);

    Map countNewBalance(Long mchId, String mchName, Long status);

    void updatePreBalance(MchAccount updateMchAccount);


//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑



}
